package com.junmoxiao.exception.controller;

import com.junmoxiao.exception.base.Result;
import com.junmoxiao.exception.base.ResultGenerator;
import com.junmoxiao.exception.base.ServiceException;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 君沫笑
 * @Description
 * @Date 2020-10-20 10:50 上午
 **/

@RestController
public class TestController {
    @GetMapping("getString")
    public Result getString(String name){

        if(StringUtils.isEmpty(name)){
            throw new ServiceException("参数为空");
        }else if ("boss".equals(name)) {
            // 这里没有查询操作，当请求参数是boss的时候，模拟成查询结果为空
            throw new ServiceException("结果为空");
        }
        // 这里模拟一下除自定义异常外的其他异常
        int i = 0;
        i = 5/i;
        return ResultGenerator.getFailResult("失败");
    }
}
